package com.leo;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Pagination;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Callback;

/**
 * @ClassName PaginationDemo
 * @Description
 * @Author wangss
 * @date 2020.05.26 10:11
 * @Version 1.0
 */
public class PaginationDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);


        Pagination pagination = new Pagination();
        pagination.setPageCount(5);
        pagination.setMaxPageIndicatorCount(10);

        pagination.setCurrentPageIndex(3);

        // 设置样式
        pagination.getStyleClass().add(Pagination.STYLE_CLASS_BULLET);

        anchorPane.getChildren().add(pagination);

        primaryStage.setScene(scene);
        primaryStage.setTitle("combobox");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        pagination.currentPageIndexProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            }
        });

        // 页数从零开始
        pagination.setPageFactory(new Callback<Integer, Node>() {
            @Override
            public Node call(Integer param) {
                if (param == 0) {

                }
                return new Button("button" + param);
            }
        });
    }
}
